'''
[有序数组的平方](https://leetcode.cn/problems/squares-of-a-sorted-array/)
'''
from typing import List
class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        l,r,i = 0,len(nums)-1,len(nums)-1
        res = [float('inf')]*len(nums)
        while l <= r:
            if nums[l]**2 <= nums[r]**2:
                res[i] = nums[r]**2
                r-=1
            elif nums[l]**2 > nums[r]**2:
                res[i] = nums[l]**2
                l+=1
            i-=1
        return res

if __name__ == '__main__':
    s = Solution()
    print(s.sortedSquares([-4,-1,0,3,10])) # [0,1,9,16,100]
    print(s.sortedSquares([-7,-3,2,3,11])) # [4,9,9,49,121]
    